package com.csdj.t309springboot.utils;

import java.util.Random;
import java.util.UUID;

public class RandomUtil {

    private final static String CHARS = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ";

    /**
     * 生成token用于登录验证
     * @return
     */
    public static String genToken(){
        String s = UUID.randomUUID().toString();
        return s.replaceAll("-","");
    }

    public static String genChars(int num){
        StringBuilder sb = new StringBuilder();
        int len = CHARS.length();
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            sb.append(CHARS.charAt(random.nextInt(len)));
        }
        return sb.toString();
    }
}
